package Player
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.utils.Dictionary;
	import Props.PropManager;
	public class VisualEntData extends BaseProcData
	{
		public var X:int;
		public var Y:int;
		public var Width:int;
		public var Height:int;
		
		public var Img:Bitmap;
		public var ImgContainer:Sprite;
		public var BmpdataFrames:Dictionary;
		public var FrameIndexes:Vector.<int>;
		public var Current:int ;	
		
		public var Layer:Sprite;		
		public var Hide:Boolean;
		
		/**
		 * 脚底坐标偏移
		 */
		public var footOffset:Point = new Point( -24, -40);	
		
		private var handleDict:Dictionary;
		
		
				
		public function VisualEntData(_id:int )
		{
			super(_id);
			ImgContainer = new Sprite();
			Img = new Bitmap();
			ImgContainer.addChild(Img);
			BmpdataFrames = new Dictionary();
			FrameIndexes = new Vector.<int>();
			ImgContainer.name = _id.toString();
			handleDict = new Dictionary();
		}
		
		public function Init(_intOfBmpDatas:Array,_default:int = 0):void
		{
			var index:int = -1;
			for each(var item:BitmapData in _intOfBmpDatas)
			{
				index++;
				BmpdataFrames[index] = item;
				FrameIndexes.push(index);
			}			
			Current = FrameIndexes[_default];
			Img.bitmapData = BmpdataFrames[Current];
			Img.x = footOffset.x;
			Img.y = footOffset.y;
		}
		
		public function AddHandler(_event:String, _handler:Function):void
		{
			handleDict[_event] = _handler;
		}
		
		public function RemoveHandler():void
		{
			for (var item:String in handleDict)
			{
			   ImgContainer.removeEventListener(item, handleDict[item]);
			}
		}
		
		public function DeActive():void
		{
			Hide = true;
			Layer.removeChild(ImgContainer);
			ImgContainer.removeChild(Img);
			ImgContainer
			ImgContainer = null;
			Img = null;
			BmpdataFrames = null;
			FrameIndexes = null;	
			RemoveHandler();
		}
		
		protected function OnMouseDown(_e:MouseEvent):void
		{
			var sprite:Sprite = _e.target as Sprite;
			trace(sprite.name);
			VisualProc.Instance.MouseDown(_e, this);
		}
		
		protected function OnMouseUp(_e:MouseEvent):void
		{
			VisualProc.Instance.MouseUp(_e, this);
		}
		
		protected function OnMouseOver(_e:MouseEvent):void
		{
			VisualProc.Instance.MouseOver(_e, this);
		}
	}
}